package com.snoob.springboot.util;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * @描述: 请求类型工具类
 * @作者: lixing
 * @日期 2019/7/20 12:57
 */
public class UserAgentUtil {
    /**
     * @描述 判断移动端/PC端
     * @作者 lixing
     * @日期 2019/7/20 12:58
     * @Param [request] 
     * @return boolean
     */
    public static boolean isMobile(HttpServletRequest request) {
        List<String> mobileAgents = Arrays.asList("ipad", "iphone os", "rv:1.2.3.4", "ucweb", "android", "windows ce", "windows mobile");
        String ua = request.getHeader("User-Agent").toLowerCase();
        for (String sua : mobileAgents) {
            if (ua.contains(sua)) {
                // 手机移动端
                return true;
            }
        }
        // PC端
        return false;
    }

    /**
     * @描述 是否微信客户端打开
     * @作者 lixing
     * @日期 2019/7/20 12:58
     * @Param [request] 
     * @return boolean
     */
    public static boolean isWechatClient(HttpServletRequest request) {
        String ua = request.getHeader("User-Agent").toLowerCase();
        return ua.contains("micromessenger");
    }

    /**
     * @描述 是否支付宝客户端打开
     * @作者 lixing
     * @日期 2019/7/20 12:58
     * @Param [request]
     * @return boolean
     */
    public static boolean isAlipayClient(HttpServletRequest request) {
        String ua = request.getHeader("User-Agent").toLowerCase();
        return ua.contains("alipayclient");
    }
}
